package com.nahan.secondapplication.VerticalViewPagerRelated;

import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.google.android.material.tabs.TabLayout;
import com.nahan.secondapplication.R;

import java.util.ArrayList;
import java.util.List;

public class VerticalViewPagerActivity extends AppCompatActivity {

    TabLayout tabLayout;
    VerticalViewPager viewPager;

    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vertical_view_pager);

        tabLayout = findViewById(R.id.ll_tab);
        viewPager = findViewById(R.id.view_pager);
        fragments.add(BlankFragment.newInstance("1", "11111"));
        fragments.add(BlankFragment.newInstance("2", "22222"));
        fragments.add(BlankFragment.newInstance("3", "33333"));
        titles.add("fragment1");
        titles.add("fragment2");
        titles.add("fragment3");
        viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                super.destroyItem(container, position, object);
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {

                return titles.get(position);
            }
        });

        tabLayout.setupWithViewPager(viewPager);
    }
}